package com.example.sekerim;

import java.io.IOException;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.MenuItemCompat;
import android.support.v7.widget.ShareActionProvider;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.jjoe64.graphview.GraphView;
import com.jjoe64.graphview.GraphViewDataInterface;
import com.jjoe64.graphview.GraphViewSeries;
import com.jjoe64.graphview.LineGraphView;

public class ExerciseDisplayFragment extends Fragment {

	private TextView mTextViewCalorieText;
	private LinearLayout mGraphlayout;
	private Button mExerciseAddButton;
	private Patient patient = new Patient();

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {             
		View rootView = inflater.inflate(R.layout.fragment_exercise_intro_page, container, false);

		
		try {
			patient = (Patient) InternalStorage.readObject(getActivity(), Constants.shared_info);
		} catch (ClassNotFoundException e) {
			Log.e("While reading", e.getMessage());
		} catch (IOException e) {
			Log.e("While reading", e.getMessage());
		}

		mTextViewCalorieText = (TextView) rootView.findViewById(R.id.exercise_intro_page_title);
		mTextViewCalorieText.setText(Constants.exercise_intro_page_title);

		GraphViewSeries exampleSeries = new GraphViewSeries(new GraphViewData[] {
				new GraphViewData(1, 2.0d)
				, new GraphViewData(2, 1.5d)
				, new GraphViewData(3, 2.5d)
				, new GraphViewData(4, 1.0d)
				, new GraphViewData(5, 1.0d)
		});

		GraphView graphView = new LineGraphView(
				getActivity() // context
				, "GraphViewDemo" // heading
				);
		
		graphView.setHorizontalLabels(new String[] {"1", "2", "3", "4", "5"});
		graphView.setVerticalLabels(new String[] {"high", "middle", "low"});
		graphView.addSeries(exampleSeries);
		
		graphView.getGraphViewStyle().setGridColor(Color.GREEN);
		graphView.getGraphViewStyle().setHorizontalLabelsColor(Color.BLACK);
		graphView.getGraphViewStyle().setVerticalLabelsColor(Color.RED);
		graphView.getGraphViewStyle().setNumHorizontalLabels(4);
		graphView.getGraphViewStyle().setNumVerticalLabels(3);
		//graphView.getGraphViewStyle().setVerticalLabelsWidth(300);

		mGraphlayout = (LinearLayout) rootView.findViewById(R.id.graph_layout);
		mGraphlayout.addView(graphView);
		
		mExerciseAddButton = (Button) rootView.findViewById(R.id.exercise_add_button);
		mExerciseAddButton.setText(Constants.exercise_add_button_text);
		mExerciseAddButton.setBackgroundColor(Color.BLUE);
		mExerciseAddButton.setTextColor(Color.RED);
		
		mExerciseAddButton.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Intent i = new Intent(getActivity(), ExerciseAddActivity.class);
				startActivity(i);
			}
		});
		
		return rootView;
	}

	public class GraphViewData implements GraphViewDataInterface {
		private double x,y;

		public GraphViewData(double x, double y) {
			this.x = x;
			this.y = y;
		}

		@Override
		public double getX() {
			return this.x;
		}

		@Override
		public double getY() {
			return this.y;
		}
	}
	


}
